package com.qf.day03_checkbox;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	private CheckBox cbEat,cbSleep,cbHit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        cbEat = (CheckBox) findViewById(R.id.cb_eat);
        cbSleep = (CheckBox) findViewById(R.id.cb_sleep);
        cbHit = (CheckBox) findViewById(R.id.cb_hit);
        
        
    }

    //点击的监听事件    onclickListner
    public void Onclick(View v){
    	//获取当前点击checkBox的状态
    	CheckBox cb =  (CheckBox) v;
    	boolean flag = cb.isChecked();
    	
    	switch (v.getId()) {
		case R.id.cb_eat:
			if(flag){//ture  选择
				Toast.makeText(MainActivity.this, "您选择了吃饭", Toast.LENGTH_SHORT).show();
			}else{//没有选择
				Toast.makeText(MainActivity.this, "您没选择了吃饭,饿着吧", Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.cb_sleep:
			if(flag){//ture  选择
				Toast.makeText(MainActivity.this, "您选择了睡觉", Toast.LENGTH_SHORT).show();
			}else{//没有选择
				Toast.makeText(MainActivity.this, "您没选择了睡觉,困着吧", Toast.LENGTH_SHORT).show();
			}
			
			break;
		case R.id.cb_hit:
			if(flag){//ture  选择
				Toast.makeText(MainActivity.this, "您选择了打豆豆", Toast.LENGTH_SHORT).show();
			}else{//没有选择
				Toast.makeText(MainActivity.this, "您没选择了打豆豆,你就是豆豆", Toast.LENGTH_SHORT).show();
			}
			break;

		default:
			break;
		}
    	
    }
    

   
}
